<%@ page import="com.hrm.dto.Envelope" %>
<%@ page import="com.hrm.entity.SalaryEntity" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.hrm.entity.EmployeeEntity" %>
<%@ page import="com.hrm.entity.AdminEntity" %><%--
  Created by IntelliJ IDEA.
  User: zekdot
  Date: 20-3-11
  Time: 下午10:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <link href="${pageContext.request.contextPath}/css/main.css" rel="stylesheet" type="text/css">
</head>
<body>
<%
    Map<String,Object> map = (Map<String, Object>) request.getAttribute("param");
    EmployeeEntity employeeEntity = (EmployeeEntity) ((Envelope)map.get("employee")).getObj();
    SalaryEntity salaryEntity = (SalaryEntity) ((Envelope)map.get("salary")).getObj();
%>
<div class="div_form">
    <h1 class="h1_style"><i class="i_h1"></i> 薪水管理</h1>
    <%
        if(employeeEntity.getStatus() != 1){
    %>
        <p class="form_p"><label class="form_label">员工id：</label>
            <input type="text" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getEId()%>">
        </p>
        <p class="form_p"><label class="form_label">基本工资：</label>
            <input type="text" class="form_input " minlength="2"  required
                   id="base" value="<%=salaryEntity.getBase()%>">
        </p>
        <p class="form_p"><label class="form_label">奖金：</label>
            <input type="text" class="form_input " minlength="2"  required
                   id="bonus" value="<%=salaryEntity.getBonus()%>">
        </p>
        <p class="form_p"><label class="form_label">扣款金额：</label>
            <input type="text" class="form_input " minlength="2"  required
                   id="deduct" value="<%=salaryEntity.getDeduct()%>">
        </p>
        <p class="form_p"><label class="form_label">实发金额：</label>
            <input type="text" class="form_input readonly" readonly="readonly"
                   id="real" disabled value="<%=salaryEntity.getBase()+salaryEntity.getBonus()-salaryEntity.getDeduct()%>">
        </p>
        <p class="form_p"><label class="form_label">考核等级：</label>
            <select id="comLevel" class="form_input1">
                <option value="A" <%=salaryEntity.getComLevel().equals("A")?"selected":""%>>A</option>
                <option value="B" <%=salaryEntity.getComLevel().equals("B")?"selected":""%>>B</option>
                <option value="C" <%=salaryEntity.getComLevel().equals("C")?"selected":""%>>C</option>
            </select>
        </p>
        <p class="but_p">
            <input type="button" id="update" value="保存" class="but_save"/>
        </p>

    <%
        }else{
    %>
        <p class="form_p"><label class="form_label">员工id：</label>
            <input type="text" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getEId()%>">
        </p>
        <p class="form_p"><label class="form_label">基本工资：</label>
            <input type="text" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getBase()%>">
        </p>
        <p class="form_p"><label class="form_label">奖金：</label>
            <input type="text" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getBonus()%>">
        </p>
        <p class="form_p"><label class="form_label">扣款金额：</label>
            <input type="text" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getDeduct()%>">
        </p>
        <p class="form_p"><label class="form_label">实发金额：</label>
            <input type="text" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getBase()+salaryEntity.getBonus()-salaryEntity.getDeduct()%>">
        </p>
        <p class="form_p"><label class="form_label">考核等级：</label>
            <input type="text" class="form_input readonly" readonly="readonly"
                   value="<%=salaryEntity.getComLevel()%>">
        </p>
    <%
        }
    %>
    <p class="but_p">
        <button class="but_save" onclick="location.href='${pageContext.request.contextPath}/employee/editInfoPage?id=<%=employeeEntity.getId()%>'">档案管理</button>
            <%
                if(session.getAttribute("user").getClass() != AdminEntity.class){
            %>
            <button class="but_save"  onclick="location.href='${pageContext.request.contextPath}/employee/posPage?id=<%=employeeEntity.getId()%>'">职位调动</button>

            <%
                }
            %>
    </p>
</div>
</body>
<script>
    function calcReal() {
        var base = eval('(' + $('#base').val() + ')');
        var bonus = eval('(' + $('#bonus').val() + ')');
        var deduct = eval('(' + $('#deduct').val() + ')');
        $('#real').val(base + bonus - deduct);
    }
    $('#base').on('change',calcReal);
    $('#bonus').on('change',calcReal);
    $('#deduct').on('change',calcReal);
    $('#update').click(function () {

        var paramJson = {'base':$('#base').val(),'bonus':$('#bonus').val(),'deduct':$('#deduct').val(),
            'comLevel':$('#comLevel').val()};
        var data = {'id':'<%=salaryEntity.getEId()%>','paramJson':JSON.stringify(paramJson)};
        // alert(JSON.stringify(data))
        $.post('updateSalary',data,function(str){
            var res = eval('(' + str + ')');
            if(res.code != 0){
                alert(res.message)
            }else{
                location.href = location.href;
            }
        })
    })
</script>
</html>
